# Contributor: Joshua Murphy <joshuamurphy@posteo.net>
maintainer="Joshua Murphy <joshuamurphy@posteo.net>"
pkgname=cemu
pkgver=2.2
pkgrel=0
_cubeb=2071354a69aca7ed6df3b4222e305746c2113f60
_imgui=f65bcf481ab34cd07d3909aab1479f409fa79f2f
pkgdesc="Wii U Emulator"
url="https://cemu.info"
arch="x86_64"
license="MPL-2.0"
makedepends="
	boost-dev
	clang
	cmake
	curl-dev
	fmt-dev
	glm-dev
	glslang-dev
	glslang-static
	gtk+3.0-dev
	hidapi-dev
	libpng-dev
	libucontext-dev
	libusb-dev
	libzip-dev
	lld
	llvm
	mesa-dev
	nasm
	openssl-dev
	pugixml-dev
	pulseaudio-dev
	rapidjson-dev
	samurai
	sdl2-dev
	speexdsp-dev
	spirv-tools-dev
	vulkan-loader-dev
	wayland-dev
	wxwidgets-dev
	zarchive-dev
	zlib-dev
	zstd-dev
	"
subpackages="$pkgname-lang"
source="$pkgname-$pkgver.tar.gz::https://github.com/cemu-project/Cemu/archive/v$pkgver.tar.gz
	cubeb-$_cubeb.tar.gz::https://github.com/mozilla/cubeb/archive/$_cubeb.tar.gz
	imgui-$_imgui.tar.gz::https://github.com/ocornut/imgui/archive/$_imgui.tar.gz
	cmake-fixes.patch
	execinfo.patch
	"
builddir="$srcdir/Cemu-$pkgver"
options="!check" # no tests

prepare() {
	default_prepare

	rmdir dependencies/cubeb
	rmdir dependencies/imgui

	ln -sfv "$srcdir"/cubeb-$_cubeb dependencies/cubeb
	ln -sfv "$srcdir"/imgui-$_imgui dependencies/imgui
}

build() {
	if [ "$CBUILD" != "$CHOST" ]; then
		local crossopts="-DCMAKE_SYSTEM_NAME=Linux -DCMAKE_HOST_SYSTEM_NAME=Linux"
	fi
	export CC=clang
	export CXX=clang++
	export LDFLAGS="$LDFLAGS -fuse-ld=lld -lucontext -lglslang"
	cmake -B build -G Ninja -Wno-dev \
		-DCMAKE_INSTALL_PREFIX=/usr \
		-DCMAKE_BUILD_TYPE=Release \
		-DENABLE_DISCORD_RPC=OFF \
		-DENABLE_VCPKG=OFF \
		-DUSE_SANITIZERS=OFF \
		$crossopts
	cmake --build build
}

package() {
	mkdir -p "$pkgdir"/usr/lib/
	cp -a bin/ "$pkgdir"/usr/lib/cemu

	install -Dm755 /dev/stdin "$pkgdir"/usr/bin/cemu <<- EOF
	#!/bin/sh
	exec /usr/lib/cemu/Cemu_release "\$@"
	EOF
}

lang() {
	pkgdesc="Translations for $pkgname"
	install_if="$pkgname=$pkgver-r$pkgrel lang"

	amove usr/lib/cemu/resources/??
}

sha512sums="
0a985a39fd08f482e0a1d6f92a4f3a7add57c08163500d7da6d9305bb8ab9e0e5d97478c1b410f394e0c1eeb942542370ebba0e04298c7d8e8b48a324b93f711  cemu-2.2.tar.gz
64a25d58f6a842947ac8ee1125574fc6a34b261e97a11a9fcdf27cccaf35dad49f12f3f2d8abb1e057932059629c3e568421cf2c09b064d76de21c1a8d8542a3  cubeb-2071354a69aca7ed6df3b4222e305746c2113f60.tar.gz
6e5bbede4435bd7248ae426eed519d702c5770ac211d2cf18c4b9f9fa7e83b901e4f80662c0f39e1d688bc3eaf674dd21c9d3e42e7324e5ab9bc16af67c13429  imgui-f65bcf481ab34cd07d3909aab1479f409fa79f2f.tar.gz
79d1fd6c733094a50e11622ec611cd06ca609bb088210ba00534f846209dc7f1f09f8308ba0c04f60b37871218155dd1865df290ecffdc4275d6c5c703da6e6a  cmake-fixes.patch
0467091365c2cdb475bb6034115be4998af71803e351e5fdf7591a640eb328a22c7cc27c2760096410e2fd597989e6986e3fb6fceb91acde5ea47cdf9ba2bce6  execinfo.patch
"
